
<script type="text/javascript">     
$(document).ready(function(){                                 

    $.expr[':'].Contains = function(a,i,m){
        return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0;
    };


     // LIVE SEARCH
    function LiveSearch(){

        var value = $.trim($("#live_search_field").val());
        if(value == "") 
            CloseLiveSearch();
        else {
            if(!($("#quick_search").is(".active"))) StartLiveSearch();

            $(".live_search_msg").html('Showing results for <i>'+value+'</i>');
            $("#content .search").each(function(){
                if( $(this).is(":has(.title:Contains("+value+"))") ) { 
                    //$(this).show();
                    $(this).addClass("search_visible").removeClass("search_hidden");
                } else if( $(this).is(":has(.title)") ) {
                    //$(this).hide();
                    $(this).addClass("search_hidden").removeClass("search_visible");
                }   
            })
            $("#content .search.search_visible:not(.search_disabled)").show();
            $("#content .search.search_hidden:not(.search_disabled)").hide();
        }
     }
    function CloseLiveSearch(){
        if($("#live_search").is(".active")){
            $("#live_search").removeClass("active");
            $(".live_search_msg").slideUp('',function(){
                $(this).hide();
            });
            $("#content .search.search_hidden").removeClass("search_hidden"); 
            $("#content .search.search_visible").removeClass("search_visible"); 
            $("#content .search:not(.search_disabled):has(.title)").show(); 
        }
     }
    function StartLiveSearch(){
        $("#live_search").addClass("active");
        $(".live_search_msg").slideDown();
     }

     $("#live_search_field").keyup(function(){
        LiveSearch();
     })  
     $("#clear_search_trigger, .live_search_msg").click(function(){
        CloseLiveSearch();
        $("#live_search_field").val('');
        $("#live_search_field").focus();
        return false;
     });




     // LIVE FILTER
     $("#show_active").change(function(){
        var key = "filter_active";
        var value = $(this).is(":checked");

        if(value) {
            $("#content .search.active:not(.search_hidden)").show();
            $("#content .search.active").removeClass("search_disabled");            
            $(this).parent("label").addClass('active');
        } else {
            $("#content .search.active").hide().addClass("search_disabled");
            $(this).parent("label").removeClass('active');
        }

        $.post("<?=site_url("admin/_live_search/set_filter")?>", { key: key, value: value},'', "html");
     });
     <? if (get_filter("filter_active") == 'false') { ?>
     $("#show_active").attr('checked', false);
     $("#show_active").change();
     <? } ?>       
      
     $("#show_inactive").change(function(){
        var key = "filter_inactive";
        var value = $(this).is(":checked");

        if(value){      
            $("#content .search.inactive:not(.search_hidden)").show();
            $("#content .search.inactive").removeClass("search_disabled");            
            $(this).parent("label").addClass('active');
        }else{
            $("#content .search.inactive").hide().addClass("search_disabled");
            $(this).parent("label").removeClass('active');
        }

        $.post("<?=site_url("admin/_live_search/set_filter")?>", { key: key, value: value},'', "html");
     });
     <? if (get_filter("filter_inactive") == 'false') { ?>
     $("#show_inactive").attr('checked', false);    
     $("#show_inactive").change();
     <? } ?>
                                      
     $("#show_pending").change(function(){
        var key = "filter_pending";
        var value = $(this).is(":checked");

        if(value){
            $("#content .search.unapproved:not(.search_hidden)").show();
            $("#content .search.unapproved").removeClass("search_disabled");            
            $(this).parent("label").addClass('active');
        }else{
            $("#content .search.unapproved").hide().addClass("search_disabled");
            $(this).parent("label").removeClass('active');
        }

        $.post("<?=site_url("admin/_live_search/set_filter")?>", { key: key, value: value},'', "html");
     });    
     <? if (get_filter("filter_pending") =='false') { ?>
     $("#show_pending").attr('checked', false);
     $("#show_pending").change();
     <? } ?>                                                                
        
})
</script>

<div id="live_search">
    <h3>quick search</h3>
    <input type="text" id="live_search_field" /> 
    <a href="#" id="clear_search_trigger"></a>
</div>

   

<div id="live_filter">
    <h3>show/hide items</h3>    
    <fieldset>
        <label class="active check_active">
            <input type="checkbox" checked="checked" id="show_active" />
            Active
        </label>
        <label class="active check_inactive">
            <input type="checkbox" checked="checked" id="show_inactive" />
            Inactive
        </label>
        <label class="active check_pending">
            <input type="checkbox" checked="checked" id="show_pending" />
            Pending approval
        </label>  
    </fieldset>                   
</div>



